<%@page contentType="text/html; charset=UTF-8" import="com.pub.database.*,java.util.*" %>
<% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); %>
<% response.setHeader("Cache.Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",0);%>
<jsp:useBean id="DataViewForm" scope="request" class="com.pub.database.DataViewForm"/>
<!-- 以下為DataView 共用設定 -->
<jsp:setProperty name="DataViewForm" property="submitMethod" value="POST"/>
<jsp:setProperty name="DataViewForm" property="pageRowCount" value="100"/>
<jsp:setProperty name="DataViewForm" property="nowPageNum"/>
<jsp:setProperty name="DataViewForm" property="dataViewAction"/>
<jsp:setProperty name="DataViewForm" property="filterCol"/>
<jsp:setProperty name="DataViewForm" property="filterValue"/>
<jsp:setProperty name="DataViewForm" property="dvOrderByFields"/>
<jsp:setProperty name="DataViewForm" property="dvOrderBySeq"/>
<!-- DataView 設定結束 -->
<%
  String strDB_Alias = request.getParameter("db_alias")==null ? "":request.getParameter("db_alias");
  String strDebug = request.getParameter("debug")==null ? "":request.getParameter("debug");
  String strSourceCharset = request.getParameter("source_charset")==null ? "":request.getParameter("source_charset");
  String strTargetCharset = request.getParameter("target_charset")==null ? "":request.getParameter("target_charset");
  String strFlowNum = request.getParameter("flow_num")==null ? "":request.getParameter("flow_num");
  String strAttTable = request.getParameter("att_table")==null ? "":request.getParameter("att_table");
  String strLang = request.getParameter("lang")==null ? "tw":request.getParameter("lang");
  String strKnd = request.getParameter("knd")==null ? "":request.getParameter("knd");

  String strLangTw = "類別,附檔名稱,檔案敘述,檔案大小(KB),上傳日期,上傳者,DQCS類別,入DQCS狀態,DQCS單號,檔案列表,離開";
  String strLangEng = "File Type,File Name,File Desc.,File Size(KB),Upload Date,Employee,DQCS Kind,DQCS Status,DQCS No,Attached List,Exit";
  String strTitle[] = new String[11];
  if(strLang!=null && strLang.equals("eng")){
    strTitle = strLangEng.split(",");
  }else if(strLang!=null && strLang.equals("tw")){
    strTitle = strLangTw.split(",");
  }

  if(strDB_Alias== null || strDB_Alias.equals("") || strFlowNum == null || strFlowNum.equals(""))
     return;


  QueryBean gqbnDAO = new QueryBean(strDB_Alias,Boolean.valueOf(strDebug),strSourceCharset,strTargetCharset);
  DataView dataView=null;
  dataView = new DataView(gqbnDAO);

  StringBuffer stbCondition = new StringBuffer();
  StringBuffer stbPageActionURI = new StringBuffer();
  stbPageActionURI.append(request.getRequestURI());
  stbPageActionURI.append("?db_alias=");
  stbPageActionURI.append(strDB_Alias);
  stbPageActionURI.append("&debug=");
  stbPageActionURI.append(strDebug);
  stbPageActionURI.append("&source_charset=");
  stbPageActionURI.append(strSourceCharset);
  stbPageActionURI.append("&target_charset=");
  stbPageActionURI.append(strTargetCharset);
  stbPageActionURI.append("&flow_num=");
  stbPageActionURI.append(strFlowNum);
  stbPageActionURI.append("&att_table=");
  stbPageActionURI.append(strAttTable);
  stbPageActionURI.append("&lang=");
  stbPageActionURI.append(strLang);
  stbPageActionURI.append("&knd=");
  stbPageActionURI.append(strKnd);

  DataViewForm.setTablesList(strAttTable+" att,sys_att_kind knd");

  stbCondition.append("att.flow_code=knd.flow_code and att.knd=knd.knd ");
  stbCondition.append("and flow_num='");
  stbCondition.append(strFlowNum);
  stbCondition.append("'");

  if(strKnd!=null && !strKnd.equals("")){
    stbCondition.append(" and att.knd='");
    stbCondition.append(strKnd);
    stbCondition.append("'");
  }

  DataViewForm.setSQLCondition(stbCondition.toString());
  DataViewForm.setOrderByFields("att.knd,file_id");
  DataViewForm.setOrderBySeq("asc");
  DataViewForm.setGroupBy(null);
  DataViewForm.setHaving(null);

  ArrayList<Hashtable<String,Object>> laltColRelation = new ArrayList<Hashtable<String,Object>>();
  Hashtable<String,Object> lhtColRelationDetail = new Hashtable<String,Object>();
  ArrayList<String> laltLinkParamList=new ArrayList<String>();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "KND_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[0]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"KND_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FILE_STORAGE");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "HIDDEN");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='hidden' name='file_storage' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FILE_STORAGE");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "ATT.FLOW_CODE");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "HIDDEN");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='hidden' name='flow_code' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FLOW_CODE");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FILE_ID");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "HIDDEN");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='hidden' name='file_id' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FILE_ID");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();
/*
  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FILE_NAME");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[1]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FILE_NAME");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%'");
*/
  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FILE_NAME");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'" + strTitle[1] + "'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "LINK");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='left'");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML,"<a target='_blank' href=");
  lhtColRelationDetail.put(dataView.STR_LINK_URI,"'/PUBPAGE/openAttach'");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE, "FILE_NAME");
  laltLinkParamList.add("db_alias=");
  laltLinkParamList.add("'"+strDB_Alias+"'");
  laltLinkParamList.add("table=");
  laltLinkParamList.add("'"+strAttTable+"'");
  laltLinkParamList.add("file_storage=");
  laltLinkParamList.add("FILE_STORAGE");
  laltLinkParamList.add("flow_code=");
  laltLinkParamList.add("FLOW_CODE");
  laltLinkParamList.add("file_id=");
  laltLinkParamList.add("FILE_ID");
  lhtColRelationDetail.put(dataView.STR_LINK_PARAM,laltLinkParamList);

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FILE_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[2]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FILE_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FILE_SIZE");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL, "TRUNC(FILE_SIZE/1024)+1");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[3]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FILE_SIZE");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='right'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "UPLOAD_DATE");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL, "TO_CHAR(UPLOAD_DATE,'yyyy/mm/dd')");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[4]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"UPLOAD_DATE");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "UPLOAD_EMPNO");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL, "(SELECT EMPLOYEE_NAME_C FROM PNL_EMPLOYEE WHERE EMPLOYEE_NO=UPLOAD_EMPNO)");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[5]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"UPLOAD_EMPNO");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "DATA_NO");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[6]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"DATA_NO");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "DATA_STATUS");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[7]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"DATA_STATUS");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "DATA_LINK_NO");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'"+strTitle[8]+"'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"DATA_LINK_NO");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  DataViewForm.setColRelationUseArrayList(laltColRelation);//將欄位相關設定殖入ActionForm
  DataViewForm.setJumpPageButtonShow(false);//是否要秀出上下頁按鈕
  DataViewForm.setPageBtnOnTop(false);//將buttonandrowsinfo秀在頂端
  DataViewForm.setPageBtnOnButtom(false);//將buttonandrowsinfo秀在底端
  DataViewForm.setFilterShow(false);//是否要秀出過濾選擇欄位
  DataViewForm.setJumpPageShow(false);//是否要秀出跳頁下拉式選單
  DataViewForm.setRowsInfoShow(true);//是否要秀出筆數資訊
  DataViewForm.setRowPageShow(false);//是否要秀出每頁筆數控制欄
  DataViewForm.setExcelShow(false);//是否要秀出轉Excelbutton
  DataViewForm.setOrderEnable(false);//是否要提供排序點選功能
  DataViewForm.setShowHeaderWhenNoData(true);//當ResultSet無資料是否要秀Header
  DataViewForm.setAddNewShow(false);//是否秀出新增鈕

  DataViewForm.setTableHeaderHtml("class='td_head_grid' align='center' width='680px'");
  //設定上一頁與下一頁按鈕的formaction(通常為母頁即本頁)
  DataViewForm.setPageActionURI(stbPageActionURI.toString());
  String strResult="";
  try{
    strResult=dataView.getOutputDataView(DataViewForm);
  }
  catch(Exception e){
    e.printStackTrace();
  }
  finally{

    try{gqbnDAO.close();gqbnDAO=null;}catch(Exception e){e.printStackTrace();}
 }

%>
<html>
<head>
<title>Upload File List</title>
<LINK HREF="/PUBPAGE/general/workflow.css" REL="STYLESHEET" TYPE="TEXT/CSS"/>
<base target='_self'/>
</head>
<body>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0" id="tbl_att_list" width="100%">
<TR>
<td nowrap class="text_head"><br /><IMG SRC="/PUBPAGE/pub_images/title/title02_bg1.gif" alt="">
 <strong><%=strTitle[9]%></strong><IMG SRC="/PUBPAGE/pub_images/title/title2_bg2.gif" alt=""><br /></td>
 </TR>
<tr><td>
<input name="exit_btn" id="exit_btn" type="button" value="<%=strTitle[10]%>" onclick="javascript:opener=null;window.close();" class="button b_normal">
</td></tr>
<tr><td>
<%=strResult==null ? "":strResult%>
</td></tr>
</table>
<script>if(opener==null){document.getElementById('exit_btn').style.display ="none";}</script>
<!--此script是用來判斷若是將此頁以iframe的方式嵌在主頁,則不需要顯示離開鍵
而若是單獨另外開一頁則需顯示離開鍵 added by kate 2008/3/19
-->
</body>
</html>
